import axios from 'axios'
import { portal_url, prehandle_url } from '../../ip-config'

const login_api = {
  // 登陆页面获取登陆验证码 @author drr ./login_register/ask_login.json
  async get_captcha() {
    const response = await axios.get('/api/base/account/captcha')

    return response.data.data
  },

  // 登陆页面请求登陆 @author drr ./login_register/login.json  /api/user/log_in
  async login(param_user_id: string, param_password: string, param_captcha_key: string, param_captcha: string) {
    console.log(param_user_id, param_password, param_captcha_key, param_captcha)

    return await axios.post('/api/base/account/login', {
      username: param_user_id,
      password: param_password,
    }, {
      params: {
        captcha_id: param_captcha_key,
        captcha_code: param_captcha,
      },
    })
  },

  // 登出
  async log_out() {
    return await axios.get('/api/base/account/logout')
  },

  // 验证码刷新
  async token_refresh() {
    console.log('token fresh url', axios.defaults.baseURL)

    return await axios.get(`${portal_url}/api/base/account/token_refresh`)
  },
}

export default login_api
